<template>
	<view class="merchant-manager-layout">
		<!-- 头部统计信息 -->
		<view class="manager-count-box">
			<view class="count-item">
				<text>总商户数(人)</text>
				<text class="count-text">{{dataInfo.merchantTotal}}</text>
			</view>
			<view class="count-bottom">
				<view class="count-item count-item-bottom">
					<text>直营商户数(人)</text>
					<text class="count-item-bottom-text">{{dataInfo.directCount}}</text>
				</view>
				<view class="count-item count-item-bottom">
					<text>非直营商户数(人)</text>
					<text class="count-item-bottom-text">{{dataInfo.notDirectCount}}</text>
				</view>
			</view>
		</view>
		<!-- 头部信息 -->
		<view class="manager-header">
			<text>我的商户</text>
			<text>仅显示直营的商户</text>
		</view>
		<!-- 我的列表 -->
		<view class="manager-card">
			<view class="manager-card-top" @tap="showMyMerchantList">
				<image src="/static/home/mer_manager_list_icon.png" mode="aspectFit"></image>
				<text class="manager-card-top-text">我的商户列表</text>
				<view class="manager-card-top-right">
					<text>总{{dataInfo.directCount}}人</text>
					<xh-icon icon="icon_jiantou"></xh-icon>
				</view>
			</view>
			<view class="manager-card-line"></view>
			<view class="manager-card-bottom">
				<view class="manager-card-bottom-item">
					<text>本月新增</text>
					<text>{{dataInfo.monthNewMerchantCount}}</text>
				</view>
				<view class="manager-card-bottom-item">
					<text>当天新增</text>
					<text>{{dataInfo.dayNewMerchantCount}}</text>
				</view>
			</view>
		</view>
		<!-- 异常代理商和未认证代理商 -->
		<view class="manager-card" style="margin-top: 30rpx;">
			<view class="manager-card-top" @tap="showFailMerchantList">
				<image src="/static/home/mer_fail_icon.png" mode="aspectFit"></image>
				<text class="manager-card-top-text">异常商户列表</text>
				<view class="manager-card-top-right">
					<text>总{{dataInfo.abnormalMerchantCount}}人</text>
					<xh-icon icon="icon_jiantou" style="margin-left: auto;"></xh-icon>
				</view>
			</view>
		</view>
		<!-- 扩展商户工具 -->
		<view style="padding: 20rpx 0;font-size: 30rpx;font-weight: bold;">
			<text>扩展商户工具</text>
		</view>
		<view class="manager-card manager-utils">
			<view class="manager-utils-item" @tap="showUtils(1)">
				<image src="/static/home/dpsj_icon@2x.png" mode="aspectFit"></image>
				<text>店铺升级</text>
			</view>
			<view class="manager-utils-item" @tap="showUtils(2)" v-if="channelStore.channelType != 'HHB'">
				<image src="/static/home/kzsh_icon@2x.png" mode="aspectFit"></image>
				<text>扩展商户</text>
			</view>
			<view class="manager-utils-item" @tap="showUtils(3)" v-if="channelStore.channelType != 'HHB'">
				<image src="/static/home/mer_device_bind_icon@2x.png" mode="aspectFit"></image>
				<text>机具绑定</text>
			</view>
		</view>
	</view>
</template>

<script setup>
	import { onShow } from '@dcloudio/uni-app'
	import { ref } from 'vue'
	import { useChannelStore } from '@/common/stores'
	import { getMerchantStatistics } from '@/common/api/api.js'

	const channelStore = useChannelStore()
	const dataInfo = ref({
		merchantTotal: 0,
		directCount: 0,
		notDirectCount: 0,
		monthNewMerchantCount: 0,
		dayNewMerchantCount: 0,
		abnormalMerchantCount: 0
	})
	// 我的商户列表
	const showMyMerchantList = () => {
		uni.navigateTo({
			url: '/pages/home/merchant-manager/merchant-list/merchant-list'
		})
	}
	// 异常商户列表
	const showFailMerchantList = () => {
		uni.navigateTo({
			url: '/pages/home/merchant-manager/abnormal-merchant/abnormal-merchant'
		})
	}
	// 选择运营工具
	const showUtils = (type) => {
		if (type == 1) {
			// 店铺升级
			uni.navigateTo({
				url: '/pages/home/merchant-manager/store-upgrade-list/store-upgrade-list'
			})
		} else if (type == 2) {
			// 扩展商户
			uni.navigateTo({
				url: '/pages/home/merchant-manager/extend-merchant/extend-merchant'
			})
		} else {
			//机具绑定
			uni.navigateTo({
				url: '/pages/home/merchant-manager/merchant-device-bind/merchant-device-bind'
			})
		}
	}
	// 获取商户统计数据
	const getMerchantStatisticsData = async () => {
		const res = await getMerchantStatistics()
		dataInfo.value = res.result
	}

	onShow(() => {
		getMerchantStatisticsData()
	})
</script>

<style lang="scss" scoped>
	.merchant-manager-layout {
		background-color: #fff;
		padding: 20rpx 30rpx;
		min-height: 100vh;

		.manager-count-box {
			background-image: url('/static/operate/yy_byjy_bg@2x.png');
			background-size: 100% 100%;
			background-repeat: no-repeat;
			padding: 40rpx;

			.count-item {
				display: flex;
				flex-direction: column;
				align-items: center;
				color: #fff;
				font-size: 30rpx;

				.count-text {
					font-size: 68rpx;
					margin-top: 10rpx;
				}
			}

			.count-bottom {
				display: flex;
				align-items: center;
				justify-content: space-around;
				margin-top: 30rpx;

				.count-item-bottom {
					font-size: 26rpx;
				}

				.count-item-bottom-text {
					font-size: 40rpx;
					margin-top: 10rpx;
				}
			}
		}

		.manager-header {
			display: flex;
			flex-direction: column;
			padding: 30rpx 0;
			font-size: 30rpx;

			text:nth-child(1) {
				font-weight: bold;
			}

			text:nth-child(2) {
				color: $xh-color-9;
				font-size: 24rpx;
				margin-top: 10rpx;
			}
		}

		.manager-card {
			border: 1px solid #eee;
			border-radius: 20rpx;
			padding: 20rpx;

			.manager-card-top {
				display: flex;
				align-items: center;

				.manager-card-top-text {
					font-size: 30rpx;
					font-weight: bold;
					margin-left: 10rpx;
				}

				.manager-card-top-right {
					display: flex;
					align-items: center;
					margin-left: auto;
					color: $xh-color-9;
					font-size: 26rpx;
				}

				image {
					width: 80rpx;
					height: 80rpx;
				}
			}

			.manager-card-line {
				margin: 20rpx 0;
				height: 1px;
				background-color: #eee;
				transform: scaleY(0.5);
			}

			.manager-card-bottom {
				display: flex;
				align-items: center;
				justify-content: space-around;

				.manager-card-bottom-item {
					display: flex;
					flex-direction: column;
					align-items: center;
					color: $xh-color-9;
					font-size: 26rpx;

					text:nth-child(2) {
						font-size: 32rpx;
						color: $xh-color-3;
						font-weight: bold;
					}
				}
			}

		}

		.manager-utils {
			display: grid;
			grid-template-columns: repeat(3, 1fr);
			grid-gap: 20rpx;

			.manager-utils-item {
				display: flex;
				flex-direction: column;
				align-items: center;
				font-size: 26rpx;
				color: $xh-color-6;

				image {
					width: 80rpx;
					height: 80rpx;
				}
			}
		}
	}
</style>